<?php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        $this->_helper->redirector->setUseAbsoluteUri(true);
    }

    public function indexAction()
    {
        $identity = Zend_Auth::getInstance()->getStorage()->read();
        if ($identity) {
            $myControler = '/' . $identity->role;
            $this->_redirect($myControler);

            return;
        }
        $form = new Application_Form_Login();
        $this->view->form = $form;
    }

    public function signUpAction()
    {
        $form = new Application_Form_SignUp();
        if ($this->getRequest()->isPost()) {
            if ($form->isValid($this->getRequest()->getPost())) {
                $mail = new Application_Model_SendFormByMail();
                $mail->send($this->getRequest()->getPost(), 'Rejestracja');

                return;
            }
        }
        $this->view->form = $form;
    }

    public function forgotPasswordAction()
    {
        $form = new Application_Form_ForgotPassword();
        if ($this->getRequest()->isPost()) {
            $getPost = $this->getRequest()->getPost();
            if ($form->isValid($getPost)) {
                $pass = new Application_Model_UpdatePartnerPassword();
                $mail = new Application_Model_SendFormByMail();
                $pass = $pass->update($getPost);
                if (TRUE === $pass[0]) {
                    $mail->send($pass[2], 'Odzyskanie hasła do konta', $pass[1]);
                    $this->view->send = TRUE;
                }

                return;
            }
        }
        $this->view->form = $form;
    }

    public function contactFormAction()
    {
        $form = new Application_Form_ContactForm();
        if ($this->getRequest()->isPost()) {
            if ($form->isValid($this->getRequest()->getPost())) {
                $mail = new Application_Model_SendFormByMail();
                $mail->send($this->getRequest()->getPost(), 'Formularz kontaktowy');

                return;
            }
        }
        $this->view->form = $form;
    }
}
